/**
 * 批量用户对话框（可用于添加和修改对话框）
 */
var ReceiveUserBatchInfoDlg = {
    id: "userTable",
    width: '1250px',
    height: '700px',
    currentLayerIndex: -1,
    cache: "",
    InfoData: {},
    userTableData: [],
    me: "",
    // seItem: null,		//选中的条目
    seItemArr: [],      //选中的条目ID数组
    selectData: null

};

/**
 * 初始化弹出框
 */
ReceiveUserBatchInfoDlg.init = function () {
    this.cache = $("#receiveUserBatchDialog").html();
    $("#receiveUserBatchDialog").html('');
};

/**
 * 清除数据
 */
ReceiveUserBatchInfoDlg.clearData = function () {
    this.InfoData = {};
    this.userTableData = [];
};

/**
 * 关闭此对话框
 */
ReceiveUserBatchInfoDlg.close = function () {
    layer.close(this.currentLayerIndex);
    ReceiveUserBatchInfoDlg.clearData();
};

/**
 * 新增打开模态框调用事件
 */
ReceiveUserBatchInfoDlg.renderAdd = function (index) {
    ReceiveUserBatchInfoDlg.initTable();
};

/**
 * 初始化整个表格
 */
ReceiveUserBatchInfoDlg.initTable = function () {
    var defaultColunms = this.initColumn();
    var bstable = new BSTable(ReceiveUserBatchInfoDlg.id, Feng.ctxPath + "/user/pageParam", defaultColunms);
    bstable.setpagination(false);
    bstable.setData({
        current: 1,
        size: 9999
    });
    this.me = bstable.init();
};

/**
 * 搜索
 */
ReceiveUserBatchInfoDlg.clickSearchUser = function () {
    var queryData = {
        current: 1,
        size: 9999
    };
    var val_search_name = $("#txt_search_name").val();
    if (val_search_name !== "" || val_search_name !== null) {
        queryData['name'] = val_search_name;
    }
    var val_search_phone = $("#txt_search_phone").val();
    if (val_search_phone !== "" || val_search_phone !== null) {
        queryData['phone'] = val_search_phone;
    }
    ReceiveUserBatchInfoDlg.me.destroy(queryData);
};

/**
 * 初始化表格的列
 */
ReceiveUserBatchInfoDlg.initColumn = function () {
    var columns = [
        {field: 'checkStatus', checkbox: true, valign: 'middle'},
        {
            title: '序号', align: 'center', valign: 'middle',
            formatter: function indexFormatter(value, row, index) {//在表格前加上序号
                return index + 1;
            }
        },
        {
            title: '头像', field: 'headImgUrl', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (value == null) {
                    value = Feng.ctxPath + '/img/vipuser.png';
                    return '<img style="width: 50px;height: 50px;" onclick="showPic(\'' + value + '\');" src="' + value + '" class="img-rounded" >';
                } else {
                    return '<img style="width: 50px;height: 50px;" onclick="showPic(\'' + value + '\');" src="' + value + '" class="img-rounded" >';
                }
            }
        },
        {title: '用户ID', field: 'id', align: 'center', valign: 'middle'},
        {title: '用户名', field: 'name', align: 'center', valign: 'middle'},
        {
            title: '性别', field: 'sex', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (value === "0") {
                    return "未知";
                } else if (value === "1") {
                    return "男";
                } else if (value === '2') {
                    return "女";
                }
            }
        },
        {title: '手机号码', field: 'phone', align: 'center', valign: 'middle'}
    ];
    return columns;
};


/**
 * 用户批量绑定优惠券
 */
ReceiveUserBatchInfoDlg.batchBindSubmit = function () {
    //复选框勾选
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length <= 0) {
        Feng.error("请选择学员");
        return;
    } else {
        var _select = [];// 去重,用户ID
        $.each(selected, function (i, user) {
            if ($.inArray(user.id, _select) === -1) {
                _select[_select.length] = user.id;
            }
        });
        ReceiveUserBatchInfoDlg.seItemArr = _select;  //用户ID字符串
        ReceiveUserBatchInfoDlg.selectData = selected;
        $("#receiveUserIds").val(_select.join(","));
        ReceiveUserBatchInfoDlg.clearData();
        ReceiveUserBatchInfoDlg.me.refresh();
    }
};






